home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / MacTCP class library / MacTCP class sources / CMacTCPDriver.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  2.8 KB  |  145 lines  |  [TEXT/KAHL]

  1. /*
  2.  
  3.   CMacTCPDriver.c
  4.   Superclass:    CObject
  5.  
  6.      The MacTCP Driver implementation (Chapter 2, MacTCP Programmer's Guide).
  7.  
  8.   Copyright © NCSA, University of Illinois;    June 2, 1992
  9.   Eric Johnson, John Newlin and Igor Livshits
  10.   
  11.   This code may be used, modified, and distributed free of charge and obligation.
  12.   
  13. */
  14.  
  15. #include    "CMacTCPDriver.h"
  16.  
  17. extern    CError*    gError;                                            //    The global error handler
  18.  
  19. /*=====================*/
  20. /*===---------------===*/
  21.  
  22. OSErr    CMacTCPDriver::IMacTCPDriver(void)
  23. Begin
  24.     short refNum= Null;                                                //    Local storage
  25.     OSErr    error;                                                            //    A possible error condition
  26.  
  27.     MakeParameters();
  28.     error= OpenDriver(kDriverName, &refNum);
  29.     
  30.     if (error != noErr)
  31.     {
  32.         gError->PostAlert(kDriverError, kCantOpen);
  33.         return error;
  34.     }
  35.     
  36.     this->refNum= refNum;
  37.     
  38.     parameterBlock->cntrlParam.ioCRefNum= refNum;
  39.     SetCompletionProc(Null);
  40.     SetMode(kSynchronous);
  41.     
  42.     return noErr;
  43. End
  44.  
  45. /*===---------------===*/
  46.  
  47. void CMacTCPDriver::Dispose(void)
  48. Begin
  49.     ForgetPtr(parameterBlock);
  50.     
  51.     inherited::Dispose();
  52. End
  53.  
  54. /*===---------------===*/
  55.  
  56. void    CMacTCPDriver::SendControlInfoToDriver()
  57. Begin
  58.     OSErr    error;
  59.  
  60.     error= PBControl(parameterBlock, True);
  61.     itsLastError= error;
  62. End
  63.  
  64. /*===---------------===*/
  65.  
  66. void    CMacTCPDriver::Process()
  67. Begin
  68.     while (parameterBlock->cntrlParam.ioResult == kInProgress)
  69.         Wait();
  70.         
  71.     itsLastError= parameterBlock->cntrlParam.ioResult;
  72. End
  73.  
  74. /*===---------------===*/
  75.  
  76. void    CMacTCPDriver::Wait(void)
  77. Begin
  78.     SubclassResponsibility();
  79. End
  80.  
  81. /*===---------------===*/
  82.  
  83. Boolean    CMacTCPDriver::Done(void)
  84. Begin
  85.     return True;                                                    //    Check the status, we are faking async calls
  86. End
  87.  
  88. /*===---------------===*/
  89.  
  90. void CMacTCPDriver::SetCompletionProc(ProcPtr myRoutine)
  91. Begin
  92.     parameterBlock->cntrlParam.ioCompletion= myRoutine;
  93. End
  94.  
  95. /*===---------------===*/
  96.  
  97. void CMacTCPDriver::SetMode(Boolean mode)
  98. Begin
  99.     fAsynchronous= mode;                                    //    True if the call is asynchronous
  100. End
  101.  
  102. /*===---------------===*/
  103.  
  104. Boolean CMacTCPDriver::GetMode(void)
  105. Begin
  106.     return fAsynchronous;                                            //    True if the call is asynchronous
  107. End
  108.  
  109. /*===---------------===*/
  110.  
  111. void CMacTCPDriver::SetSizeOfParameters(void)
  112. Begin
  113.     SubclassResponsibility();
  114. End
  115.  
  116. /*===---------------===*/
  117.  
  118. void CMacTCPDriver::MakeParameters()
  119. Begin
  120.     ParmBlkPtr    pb= Null;
  121.  
  122.     SetSizeOfParameters();
  123.     pb= (ParmBlkPtr)NewPtrClear(sizeOfParameters);
  124.     parameterBlock= pb;                                                //    Set up the parameter block
  125. End
  126.  
  127. /*===---------------===*/
  128.  
  129. void CMacTCPDriver::SetParameters(ParmBlkPtr newParameters)
  130. Begin
  131.     BlockMove(newParameters, parameterBlock, sizeOfParameters);
  132. End
  133.  
  134. /*===---------------===*/
  135.  
  136. void CMacTCPDriver::GetParameters(ParmBlkPtr* duplicateParameters)
  137. Begin
  138.     if (!(*duplicateParameters))
  139.         *duplicateParameters= (ParmBlkPtr)NewPtr(sizeOfParameters);
  140.         
  141.     BlockMove(parameterBlock, *duplicateParameters, sizeOfParameters);
  142. End
  143.  
  144. /*===---------------===*/
  145. /*=====================*/